package com.atguigu.mapreduce.solution;

import org.apache.hadoop.io.Text;
import org.apache.hadoop.mapreduce.Reducer;

import java.io.IOException;

public class SolutionReducer1 extends Reducer<Text, Text, Text, Text> {

    private final Text result = new Text();
    private final StringBuilder sb = new StringBuilder();

    @Override
    protected void reduce(Text key, Iterable<Text> values, Reducer<Text, Text, Text, Text>.Context context) throws IOException, InterruptedException {
        sb.setLength(0);
        values.forEach(str -> sb.append(str).append(','));
        result.set(sb.substring(0, sb.length() - 1));
        context.write(key, result);
    }
}
